﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace Happy.Web.Mvc.Utils
{
    /// <summary>
    /// 路径工具。
    /// </summary>
    public static class UrlUtil
    {
        public static string GetRelativeUrl(string filename)
        {
            var rootPath = HttpContext.Current.Server.MapPath("/");
            if (!filename.StartsWith(rootPath))
            {
                throw new InvalidOperationException(Resource.Messages.Error_CanNotGetRelativeUrl);
            }

            return "/" + filename.Remove(0, rootPath.Length).Replace('\\', '/');
        }
    }
}
